<!DOCTYPE html>
<html>
<head>
	<?php
require_once("../inc/constants.inc.php");
require_once("../inc/connection.php");
session_start();
?>
</head>
<body>
<?php
if(isset($_POST['resetPassword']))
	{
		$email = fiter_input($_POST["email"]);
		$password = mysql_real_escape_string($_POST["password"]);
		$confirmPassword =  mysql_real_escape_string($_POST["confirmPassword"]);
		if(empty($email) || empty($password) || empty($confirmPassword))
			{
				header("Location: ../reset-user-password.php?isEmpty=yes");
				exit(0);
			}
		if(!filter_var($email, FILTER_VALIDATE_EMAIL))
			{
				header("Location: ../reset-user-password.php?isInvalid=yes&email=$email");
				exit(0);
			}
		elseif($password != $confirmPassword)
			{
				header("Location: ../reset-user-password.php?isNotMatch=yes&email=$email");
				exit(0);
			}
		else
			{
				$password = md5(fiter_input($_POST["password"]));
				$result = mysql_query("SELECT * FROM login_details WHERE UserEmail='$email'");
				while($row = mysql_fetch_array($result))
					{
						$emailPresent = true;
						echo $row['UserEmail'];
					}
				if($emailPresent)
					{
						echo "ssssssssssss";
						$q = "UPDATE `login_details` SET UserPassword='$password' WHERE UserEmail='$email'";
						if(mysql_query($q))
							{	
								header("Location: ../dashboard.php?isUpdated=yes&isReset=yes");
								exit(0);
							}
					}
				else
					{
						header("Location: ../reset-user-password.php?isWrongEmail=yes&email=$email");
						exit(0);
					}
			}
	}
		
function fiter_input($data)
	{
		 $data = trim(mysql_real_escape_string($data));
		 $data = htmlspecialchars($data);
		 return $data;
	}
?>

</body>
</html>